<?php

/**
 * Created by PhpStorm.
 * User: CCA
 * Date: 2019/10/10
 * Time: 9:38
 */
namespace app\api;
use app\common\model\Member;
use app\common\model\Pointcart;
use app\common\model\Pointorder;
use app\common\model\Token;
use app\common\model\Voucher;
use app\home\controller\BaseMall;
use think\Controller;
use think\Request;


class Base2Controller extends BaseMall
{

    public $user_info = null;
    public $user_id = null;

    public function __construct(Request $request = null)
    {
        parent::__construct($request);
        $white_methods = [
            'forgetpwd','fulogin','get_area_list','register','xieyi','getskillid',
            'getbrand', 'getqution',
             'getbanner','type','upload','gettypes'
        ]; //法免登陆白名单
        $methods = $request->action();  #获取所有方法
//        var_dump($methods);
        if (!in_array($methods,$white_methods))
        {
            if (!($token = input('token')))
            {
                return json_fail_return('缺少token',[],300);
            }
            $tokenInfo = db('fuwu_token')->where(['token'=>$token])->find();
            if (!$tokenInfo){
                return json_fail_return('token验证失败',[],300);
            }
            if($tokenInfo['expire_time']<time()){
                return json_fail_return('token已过期',[],300);
            }
            $this->user_id = $tokenInfo['user_id'];
            $this->tokeid = $tokenInfo['id'];
        }
    }

    protected function buildAccessToken($lenght = 32)
    {
        //生成AccessToken
        $str_pol = "1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ123456789abcdefghijklmnopqrstuvwxyz";
        return substr(str_shuffle($str_pol), 0, $lenght);

    }

}